<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Contract-add</title>
    <!-- 引入layui 样式-->
    <link rel="stylesheet" href="../../static/layer/css/layui.css"/>
    <script type="text/javascript" src="../../static/layer/layui.js"></script>
    <script type="text/javascript" src="../../static/js/common/queryUtils.js"></script>

    <script src="../../static/ujs/depot/depot_list_new.js"></script>
</head>

<style>
    /* 导航样式 */
    .layui-tab {
        margin: 0;
    }

    .layui-tab-title {
        height: auto;
    }

    .layui-tab-title li {
        padding: 0;
    }

    .layui-tab-card > .layui-tab-title .layui-tab-bar {
        height: 60px;
        line-height: 60px;
    }

    .layui-nav .layui-nav-item a {
        color: #666666;
    }

    .layui-nav .layui-nav-item a:hover {
        color: #000000;
    }

    .layui-tab-card > .layui-tab-title .layui-this {
        background-color: transparent;
    }

    .layui-tab-card > .layui-tab-title .layui-this a {
        color: #000000;
    }

    .layui-tab-card > .layui-tab-title .layui-this::after {
        content: '';
        bottom: 0;
        width: 100%;
        position: absolute;
        left: 0;
        top: 55px;
        height: 6px;
        background-color: #5FB878;
        transition: all .2s;
        -webkit-transition: all .2s;
    }

    .layui-anim-upbit {
        max-height: 300px;
        overflow-y: auto;
    }

    .class_left {
        float: right;
    }

    .title_class li {
        padding-left: 15px;
    }

</style>
<body>
<div class="layui-tab layui-tab-card operateTable">
    <ul class="layui-nav layui-tab-title layui-bg-gray">
        <li class="layui-nav-item"><a href="javascript:;">停车场</a>
            <dl class="layui-nav-child"></dl>
        </li>
    </ul>
</div>

<div class="layui-tab layui-tab-brief operateTable2" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title title_class">
        <li class="AUTH-TCCGL_MKCK layui-this layui-maika" data-type="changeType" data-id="maika">卖卡</li>
        <li class="AUTH-TCCGL_BYNKCK layui-baoyue" data-type="changeType" data-id="baoyue">包月年卡</li>
        <li class="AUTH-TCCGL_LSXSFCK layui-linshi" data-type="changeType" data-id="linshi">临时性收费</li>
    </ul>
    <div class="layui-tab-content">

    </div>
    <table id="sellCardId" lay-filter="sellCard"></table>
    <!--  <div style="display: none;" id="dclbar">
          <a class="layui-btn layui-btn-primary layui-btn-mini AUTH-CWQX_ZDCK" lay-event="detail">查看</a>
      </div>-->
</div>

</body>

<script>
    var table;
    var buildingId = "";
    var businessId = "";
    var PARK_ID = "";
    var flagboolean = false;
    var sellType = "maika";
    var funType = "";
    var valName = "";
    var typeName = "addBuilding";
    layui.use(['jquery', 'table', 'form', 'layer', 'element'], function () {
        table = layui.table;
        var $ = layui.jquery,
            element = layui.element, //导航的hover效果、二级菜单等功能，需要依赖element模块
            form = layui.form;
        var type;
        //监听表格复选框选择
        table.on('checkbox(business)', function (obj) {
            console.log(obj)
        });

        var active = {
            addBuilding: function () {
                layer.open({
                    type: 2,
                    title: '新增项目',
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['900px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'depot_add.html?type=sell_card&buildingId=' + buildingId + '&businessId=' + businessId + '&PARK_ID=' + PARK_ID
                });
            },
            addBaoyueCard: function () {
                debugger
                layer.open({
                    type: 2,
                    title: '新增项目',
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1050px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'depot_byCard_add.html?type=addBaoyueCard&buildingId=' + buildingId + '&businessId=' + businessId + '&PARK_ID=' + PARK_ID
                });
            },
            addIntermCard: function () {
                debugger
                layer.open({
                    type: 2,
                    title: '新增项目',
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1050px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'depot_interim_add.html?type=addIntermCard&buildingId=' + buildingId + '&businessId=' + businessId + '&PARK_ID=' + PARK_ID
                });
            },

            changeBusiness: function (obj) { //获取选中数据

                flagboolean = true;
                PARK_ID = obj.data("id");
                businessId = obj.parent().parent().data("id");
                buildingId = QueryUtils.GetQueryString('activebuildingID');
                if (sellType == "maika") {
                    reloadTable();

                } else if (sellType == "linshi") {
                    linshi();

                } else if (sellType == "baoyue") {
                    baoyue();
                } else {
                    reloadTable();
                }


            }, reload: function () {
                var name = $('#filter-id').val();
                reloadTable(name);
            },
            changeType: function (obj) { //获取选中数据
                var funType = obj.data("id");
                buildingId = QueryUtils.GetQueryString('activebuildingID');
                $(".AUTH-TCCGL_BYNKXZ").removeClass("AUTH-TCCGL_BYNKXZ");
                $(".AUTH-TCCGL_LSXSFXZ").removeClass("AUTH-TCCGL_LSXSFXZ");
                $(".AUTH-TCCGL_MKXZ").removeClass("AUTH-TCCGL_MKXZ");
                $(".operateDiv").empty();
                $(".operateDiv").append('<button class="layui-btn class_left operateTable" data-type="addBuilding"><i class="layui-icon"></i> 添加卖卡</button>');
                if (funType == "baoyue") {
                    $(".nameType").show();
                    $(".search_class").show();
                    sellType = "baoyue";
                    $(".park_type").find(".operateTable").attr("data-type", "addBaoyueCard");
                    $(".park_type").find(".operateTable").addClass("AUTH-TCCGL_BYNKXZ");
                    $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加包月年卡');
                    typeName = "addBaoyueCard";

                    $(".nameType").val("");
                    valName = "";
                    baoyue();
                } else if (funType == "linshi") {
                    $(".nameType").hide();
                    $(".search_class").hide();
                    $(".park_type").find(".operateTable").attr("data-type", "addIntermCard");
                    $(".park_type").find(".operateTable").addClass("AUTH-TCCGL_LSXSFXZ");
                    $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加临时性消费');
                    typeName = "addIntermCard";
                    $(".nameType").val("");
                    valName = "";

                    sellType = "linshi";
                    linshi();
                } else if (funType == "maika") {
                    typeName = "addBuilding";
                    $(".nameType").show();
                    $(".search_class").show();
                    $(".park_type").find(".operateTable").attr("data-type", "addBuilding");
                    $(".park_type").find(".operateTable").addClass("AUTH-TCCGL_MKXZ");
                    $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加卖卡');
                    $(".nameType").val("");
                    valName = "";

                    sellType = "maika";
                    reloadTable(null);
                }

                initAuthUtil();
                $('.operateTable').on('click', function () {
                    var type = $(this).attr("data-type");
                    active[type] ? active[type].call(this) : '';
                });
            }
        }

        buildingId = QueryUtils.GetQueryString('activebuildingID');
        var dataSo = {};
        dataSo.BUILDING_ID = buildingId;
        $.ajax({
            url: "/parkController/findlist",
            data: dataSo,
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                debugger
                if (res.errcode === "0") {
                    for (var j = 0; j < res.data.length; j++) {
                        var child = '<dd data-type="changeBusiness" data-id="' + res.data[j].ID + '"><a href="javascript:;">' + res.data[j].PARK_NAME + '</a></dd>';
                        $(".layui-nav-item").find(".layui-nav-child").append(child);
                    }
                    $('.layui-nav .layui-nav-item dl dd').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type]($(this)) : '';
                    });
                    element.init();
                    $(".layui-nav .layui-nav-item dl dd").eq(0).click();
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });

        $('.operateTable').on('click', function () {
            var type = $(this).attr("data-type");
            active[type] ? active[type].call(this) : '';
        });

        $('.operateTable2 ul li').on('click', function () {
            var type = $(this).attr("data-type");
            active[type] ? active[type]($(this)) : '';
        });

    });

    function search(the) {
        var val = $(the).parent().find(".nameType").val();
        valName = val;
        if (sellType == "baoyue") {
            sellType = "baoyue";
            $(".nameType").show();
            $(".search_class").show();
            $(".park_type").find(".operateTable").attr("data-type", "addBaoyueCard");
            $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加包月年卡');
            baoyue();
        } else if (sellType == "linshi") {
            sellType = "linshi";

            $(".nameType").hide();
            $(".search_class").hide();
            $(".park_type").find(".operateTable").attr("data-type", "addIntermCard");
            $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加临时性消费');
            linshi();
        } else if (sellType == "maika") {
            sellType = "maika";
            $(".nameType").show();
            $(".search_class").show();
            $(".park_type").find(".operateTable").attr("data-type", "addBuilding");
            $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加卖卡');
            reloadTable(null);
        } else {
            sellType = "maika";
            $(".nameType").show();
            $(".search_class").show();
            $(".park_type").find(".operateTable").attr("data-type", "addBuilding");
            $(".park_type").find(".operateTable").html(' <i class="layui-icon"></i> 添加卖卡');
            reloadTable(null);
        }
    }


    //临时性消费
    function linshi() {
        var data = {};
        data.BUILDING_ID = buildingId;
        data.PARK_ID = PARK_ID;
        data.PRICE_TYPE = "3";
        data.valName = valName;
        activebuildingID = QueryUtils.GetQueryString('activebuildingID');

        if (!!name) {
            data.ROOM_NUM = name;
        }
       

        table.render({
            elem: '#sellCardId'
            , url: '/billController/listInterim'
            , where: data
            , cols: [[
                {checkbox: true, LAY_CHECKED: true} //默认全选
                , {
                    field: 'PART_START',
                    event: 'setSign',
                    title: '开始时间',
                    width: 200,
                    sort: 'true',
                    templet: '#weishouTpl'
                }
                , {field: 'PART_END', event: 'setSign', title: '结束时间', width: 200, sort: 'true'}
                , {field: 'TYPE_SHOU', event: 'setSign', title: '类型', width: 200, sort: 'true'}
                , {field: 'PARK_OR_PRICE', event: 'setSign', align: 'right', title: '金额/张数', width: 200, sort: 'true'}
                , {field: 'CREATE_DATE', event: 'setSign', title: '操作时间', width: 200, sort: 'true'}
                , {field: 'CREATE_ID', event: 'setSign', title: '操作人', width: 250}
                /*, {fixed: 'right', width: 200, align: 'center', title: '操作', toolbar: '#dclbar'}*/

            ]]
            , id: 'szlbID'
            , page: true
            , height: 'full-180'
            , limit: '10'
        });
    }

    //包月
    function baoyue() {
        var data = {};
        data.BUILDING_ID = buildingId;
        data.PARK_ID = PARK_ID;
        data.PRICE_TYPE = "4";
        data.valName = valName;
        activebuildingID = QueryUtils.GetQueryString('activebuildingID');

        if (!!name) {
            data.ROOM_NUM = name;
        }

        table.render({
            elem: '#sellCardId'
            , url: '/billController/listSellCards'
            , where: data
            , cols: [[
                {checkbox: true, LAY_CHECKED: true} //默认全选
                , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 120, sort: 'true', templet: '#weishouTpl'}
                , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120, sort: 'true'}
                , {field: 'COMPANY_NAME', event: 'setSign', title: '承租方', width: 120, sort: 'true'}
                , {field: 'PARK_CARD', event: 'setSign', title: '张数', width: 120, sort: 'true'}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '金额', width: 120, align: 'right', sort: 'true'}
                , {
                    field: 'PART_START',
                    event: 'setSign',
                    title: '开始时间',
                    width: 120,
                    sort: 'true',
                    templet: '#weishouTpl'
                }
                , {field: 'PART_END', event: 'setSign', title: '结束时间', width: 120, sort: 'true'}
                , {field: 'ALLOT_BILL', event: 'setSign', title: '收款类型', width: 140, sort: 'true'}
                , {field: 'CREATE_DATE', event: 'setSign', title: '操作时间', width: 140, sort: 'true'}
                , {field: 'CREATE_ID', event: 'setSign', title: '操作人', width: 140}

                /*     , {fixed: 'right', width: 200, align: 'center', title: '操作', toolbar: '#dclbar'}*/

            ]]
            , id: 'szlbID'
            , page: true
            , height: 'full-180'
            , limit: '10'
        });
    }

    //买卡
    function reloadTable(name) {
        var data = {};
        data.BUILDING_ID = buildingId;
        data.PARK_ID = PARK_ID;
        data.valName = valName;
        data.PRICE_TYPE = "2";
        activebuildingID = QueryUtils.GetQueryString('activebuildingID');

        if (!!name) {
            data.ROOM_NUM = name;
        }
        console.log(data)
        table.render({
            elem: '#sellCardId'
            , url: '/billController/listSellCards'
            , where: data
            , cols: [[
                {checkbox: true, LAY_CHECKED: true} //默认全选
                , {field: 'ROOM_NUM', event: 'setSign', title: '项目编号', width: 160, sort: 'true', templet: '#weishouTpl'}
                , {field: 'BYNAME', event: 'setSign', title: '别名', width: 180, sort: 'true'}
                , {field: 'COMPANY_NAME', event: 'setSign', title: '承租方', width: 160, sort: 'true'}
                , {field: 'PARK_CARD', event: 'setSign', title: '张数', width: 160, sort: 'true'}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '金额', width: 160, align: 'right', sort: 'true'}
                , {field: 'ALLOT_BILL', event: 'setSign', title: '收款类型', width: 160, sort: 'true'}
                , {field: 'CREATE_DATE', event: 'setSign', title: '操作时间', width: 160, sort: 'true'}
                , {field: 'CREATE_ID', event: 'setSign', title: '操作人', width: 180}
                /*  , {fixed: 'right', width: 200, align: 'center', title: '操作', toolbar: '#dclbar'}*/

            ]]
            , id: 'szlbID'
            , page: true
            , height: 'full-180'
            , limit: '10'

        });
    }

    //表单刷新
    function reloadtable() {
        table.reload('roomTableid');
    }
</script>
</html>